const fp = require('lodash/fp')

class Maybe {
    static of (array) {
        return new Maybe(array)
    }

    constructor(array) {
        this._value = array
    }

    map(fn) {
        this._value = fp.map(fn, this._value)
        return this
    }

    getFirst(fn) {
        this._value = fn && fn(this._value)
        return this
    }

    getNumber() {
        if (!this._value) {
            return this
        }
        let reg = /\d+(\.?\d*)/g
        this._value = this._value.match(reg) ? this._value.match(reg)[0] : undefined
        return this
    }
}

class Container {
    static of (array) {
        return new Container(array)
    }

    constructor(array) {
        this._value = array
    }

    map(fn) {
        this._value = fn && fn(this._value)
        return this
    }
}

module.exports = {
    Maybe,
    Container
}